﻿<UserControl x:Class="Tum.PDE.ToolFramework.Modeling.Visualization.Controls.Dependencies.GraphDependenciesViewControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" TextOptions.TextFormattingMode="Display" 
             d:DesignHeight="300" d:DesignWidth="300"
             xmlns:view="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.Controls.Dependencies"
             xmlns:dd="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.Controls.Attached.DragDrop"
             xmlns:converter="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.Converters"
             xmlns:vmAtt="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.ViewModel.Attached"
             
             vmAtt:ViewModelAttachedCommands.Loaded="{Binding Path=LoadedCommand, Mode=OneWay}"
             >
    <UserControl.Resources>
        <ResourceDictionary>
            <SolidColorBrush Color="#FF00A8FF" x:Key="SelectionBorderBrush"/>
            <SolidColorBrush Color="#FF99CCFF" x:Key="SelectionBrush2"/>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" x:Key="SelectionBrush">
                <GradientStop Color="White"/>
                <GradientStop Color="#FF99CCFF" Offset="1"/>
            </LinearGradientBrush>

            <converter:BoolToOppositeConverter x:Key="BoolToOppositeConverter"/>

            <!-- SelectionDecorator Default Template -->
            <ControlTemplate x:Key="SelectionDecoratorTemplate" TargetType="{x:Type Control}">
                <Grid SnapsToDevicePixels="true">
                    <Rectangle Stroke="{StaticResource SelectionBrush2}" StrokeThickness="1" StrokeDashArray="3 6" Margin="-5 -5 -5 -5"
                       VerticalAlignment="Stretch" HorizontalAlignment="Stretch" StrokeDashCap="Square"
                       IsHitTestVisible="False" Focusable="False"/>
                </Grid>
            </ControlTemplate>

            <ControlTemplate x:Key="ShowDependenciesDecoratorTemplate" TargetType="{x:Type Control}">
                <Grid SnapsToDevicePixels="true">
                    <Button Command="{Binding Path=Diagram.ShowDependenciesCommand}" BorderThickness="0" Background="Transparent" BorderBrush="Transparent"
                            HorizontalAlignment="Right" VerticalAlignment="Top" Width="20" Height="20" Margin="-15, -10, 0, 0" Padding="0">
                        <Image Width="16" Height="16"
                               Source="/Tum.PDE.ToolFramework.Images;component/Ribbon/Refresh-16.png"/>
                    </Button>
                </Grid>
            </ControlTemplate>

             <Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle">
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                                <ContentPresenter />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
        <Grid>
            <view:GraphicalDependenciesItemsControl ItemsSource="{Binding Path=Children, Mode=OneWay}" 
                                                    SelectedItems="{Binding Path=SelectedItemsData, Mode=TwoWay}"
                                                    dd:DragDrop.IsDropTarget="True"
                                                    dd:DragDrop.DropHandler="{Binding}"
                                                    HorizontalAlignment="Stretch"
                                                    VerticalAlignment="Stretch" Background="White">
                <view:GraphicalDependenciesItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <view:GraphicalDepenedenciesCanvas/>
                    </ItemsPanelTemplate>
                </view:GraphicalDependenciesItemsControl.ItemsPanel>
                <view:GraphicalDependenciesItemsControl.ItemContainerStyle>
                    <Style TargetType="{x:Type view:GraphicalDependenciesItem}">
                        <Setter Property="Control.Width" Value="{Binding Path=Width, Mode=OneWay}"/>
                        <Setter Property="Control.Height" Value="{Binding Path=Height, Mode=OneWay}"/>
                        <Setter Property="Canvas.Left" Value="{Binding Path=AbsoluteLeft, Mode=OneWay}"/>
                        <Setter Property="Canvas.Top" Value="{Binding Path=AbsoluteTop, Mode=OneWay}"/>

                        <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>
                        <Setter Property="MinWidth" Value="5"/>
                        <Setter Property="MinHeight" Value="5"/>
                        <Setter Property="SnapsToDevicePixels" Value="True"/>

                        <Setter Property="Template" >
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type view:GraphicalDependenciesItem}">
                                    <Grid>
                                        <!-- PART_SelectionDecorator -->
                                        <Control x:Name="PART_SelectionDecorator" 
                                            Visibility="Collapsed"
                                            Template="{StaticResource SelectionDecoratorTemplate}"/>

                                        <ContentPresenter />

                                        <Control x:Name="PART_ShowDependenciesDecorator" 
                                            Visibility="Collapsed"
                                            Template="{StaticResource ShowDependenciesDecoratorTemplate}"/>
                                    </Grid>
                                    <ControlTemplate.Triggers>
                                        <!-- Is selected trigger -->
                                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=IsSelected}" Value="True">
                                            <Setter TargetName="PART_SelectionDecorator" Property="Visibility" Value="Visible"/>
                                            <Setter TargetName="PART_ShowDependenciesDecorator" Property="Visibility" Value="Visible"/>
                                        </DataTrigger>

                                        <!--<DataTrigger Binding="{Binding Path=TransitionName, Mode=OneTime}" Value="Star">
                                            <Setter TargetName="transitionPresenter" Property="Transition" Value="{StaticResource StarTransition}"/>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding Path=TransitionName, Mode=OneTime}" Value="HorizontalWipe">
                                            <Setter TargetName="transitionPresenter" Property="Transition" Value="{StaticResource HorizontalWipeTransition}"/>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding Path=TransitionName, Mode=OneTime}" Value="FadeAndGrow">
                                            <Setter TargetName="transitionPresenter" Property="Transition" Value="{StaticResource FadeAndGrowTransition}"/>
                                        </DataTrigger>-->

                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </view:GraphicalDependenciesItemsControl.ItemContainerStyle>
            </view:GraphicalDependenciesItemsControl>

            <Grid HorizontalAlignment="Right" VerticalAlignment="Top" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <Button Height="32" Grid.Column="0" Command="{Binding Path=RefreshCommand}" Padding="0" Focusable="False" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" Width="100" HorizontalAlignment="Center" VerticalAlignment="Top">
                    <StackPanel Orientation="Horizontal">
                        <Image Margin="5" Source="pack://application:,,,/Tum.PDE.ToolFramework.Images;component/Ribbon/Refresh-16.png"/>
                        <TextBlock Text="Refresh" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>

                <Expander Header="Dependency Types" IsExpanded="False" Margin="3" Grid.Column="1" VerticalAlignment="Top">
                    <ListBox ItemsSource="{Binding Path=FilterItemVMs}" MaxWidth="260" MaxHeight="400" BorderBrush="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                         ItemContainerStyle="{StaticResource ContainerStyle}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding Path=IsFiltered, Mode=TwoWay, Converter={StaticResource BoolToOppositeConverter}}">
                                    <CheckBox.Content>
                                        <TextBlock Margin="5" Text="{Binding Path=Title, Mode=OneWay}"
                                               ToolTip="{Binding Path=Title, Mode=OneWay}"
                                               TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" MaxWidth="240"/>
                                    </CheckBox.Content>
                                </CheckBox>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Expander>
            </Grid>
        </Grid>
    </ScrollViewer>
</UserControl>
